<%
   response.setHeader("Content-disposition","attachment; filename=sheet1.xls");
%>
<%@ taglib uri="/WEB-INF/eam-tag.tld" prefix="eam" %>
<%@ page import="com.sbdcpn.page.utils.RequestUtil,
				 com.sbdcpn.business.wzmis.base.SjTotalBO,
				 java.util.List,
				 java.text.DecimalFormat,
				 java.util.Map" %>
<%/*---设置字符集---*/%>
<eam:PageLanguage />
<%/*---设置字符集---*/%>
<%
	int fontSize = 25;
	DecimalFormat DECIMALFORMAT = new DecimalFormat("0.00");
	String month = RequestUtil.getStringParameter(request ,"month" ,"");
	int ctryType = Integer.parseInt(RequestUtil.getStringParameter(request ,"ctryType" ,"0"));
	String funcid = RequestUtil.getStringParameter(request ,"funcid" ,"");
	boolean isStock = false;
	if ("sjtotal_stock".equals(funcid)){
		isStock = true;
	}

	SjTotalBO sjTotalBO = new SjTotalBO();
	List[] returnList = sjTotalBO.getTotal(month, ctryType, isStock);
	List titleList = returnList[0];
	List contentList = returnList[1];

	int totalWidth = 0;
	int totalCol = 0;
	if (!titleList.isEmpty()){
		totalWidth += 20;
		totalCol += 3;
		List firstList = (List)titleList.get(0);
		List secondList = (List)titleList.get(1);
		for(int i = 0; i < 2; i++){
			String[] col = (String[])firstList.get(i);
			totalWidth += col[0].length() * fontSize;
		}
		totalCol += secondList.size();
		for(int i = 0; i < secondList.size(); i++){
			String[] col = (String[])secondList.get(i);
			totalWidth += col[0].length() * fontSize;
		}
	}
%>
<HTML xmlns:x="urn:schemas-microsoft-com:office:excel">
<HEAD>
	<TITLE>
<% 		if (isStock){ %>
		<eam:message key="title.sjtotal_stock"/>
<%
		}
		else{
%>
		<eam:message key="title.sjtotal_consume"/>
<%
		}
%>
	</TITLE>
	<script src="<%=CONTEXTPATH%>/utility/class/cutil.js"></script>
	<style>
	td.gridHead{
		text-align: center;
		font-size: 9pt;
	}
	tr.gridData{
		font-size: 9pt;
	}
	</style>
</HEAD>
<BODY>
	<TABLE class="gridTbl" width="800">
	  <tr><td></td></tr>
	</TABLE>
	<form method="post" action="" name="frmtotal" id="frmtotal"></form>
	<table class="gridTbl">
		<tr>
<%
	if (totalCol == 0){
%>
			<td bgcolor="#ffffff" align="center">
<%
	}
	else{
%>
			<td colspan=<%= totalCol%> bgcolor="#ffffff" align="center">
<%
	}
%>
				<b>
					<font size="3" font-family="楷体_gb2312" color="black">
<% 					if (isStock){ %>
					<eam:message key="title.sjtotal_stock"/>
<%
					}
					else{
%>
					<eam:message key="title.sjtotal_consume"/>
<%
					}
%>
					</font>
				</b>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
<div style=" padding-left: 0px; padding-bottom: 0px; width: 100%; height: 83%; color:#ffffff; margin-top:13px; overflow: auto;">
<!-- sbdhtc:datagrid id="totalgrid" -->
	<table id="tab" class="gridTbl" border="1">
		<thead>
<%
	for(int i = 0; i < titleList.size(); i++){
%>
		<tr class="gridHead">
<%		if (i == 0){ %>
			<td width="20px" align="center" rowspan="2" class="gridHead">No.</td>
<%
		}
		List colList = (List)titleList.get(i);
		for(int j = 0; j < colList.size(); j++){
			String[] col = (String[])colList.get(j);
			int width = col[0].length() * fontSize;
			if (i == 0 && j == 1){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" width="200px" align="center" class="gridHead"><%= col[0]%></td>
<%
			}
			else if (i == 0 && j > 1){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="center" class="gridHead"><%= col[0]%></td>
<%
			}
			else{
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" width="<%= width%>px" align="center" class="gridHead"><%= col[0]%></td>
<%
			}
		}
%>
		</tr>
<%
	}
%>
		</thead>
		<tbody>
<%
	for(int i = 0; i < contentList.size(); i++){
%>
		<tr class="gridData">
<% 		if (i !=  (contentList.size()-1)){ %>
			<td class="gridHead"><%= (i+1)%></td>
<%
		}
		else{
%>
			<td class="gridHead">&nbsp;</td>
<%
		}
		List colList = (List)contentList.get(i);
		for(int j = 0; j < colList.size(); j++){
			String[] col = (String[])colList.get(j);
			if (i !=  (contentList.size()-1) && j < 2){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="left" x:str><%= col[0]%></td>
<%
			}
			else if (i !=  (contentList.size()-1) && j > 1){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="right"><%= col[0]%></td>
<%
			}
			else if (i ==  (contentList.size()-1) && j == 0){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="right"><b><%= col[0]%></b></td>
<%
			}
			else if (i ==  (contentList.size()-1)){
%>
			<td colspan="<%= col[1]%>" rowspan="<%= col[2]%>" align="right"><%= DECIMALFORMAT.format(Double.parseDouble(col[0]))%></td>
<%
			}
		}
%>
		</tr>
<%
	}
%>
		</tbody>
	</table>
</div>
<!-- /sbdhtc:datagrid-->
</BODY>
</HTML>